<template>
    <view>
        <form @reset="formReset" @submit="formSubmit">
            <view class="head" :style="'background:' + color">
                <navigator class="text" openType="redirect" url="txmx">提现明细</navigator>
                <view class="headmoney">{{ commission }}</view>
                <view class="headwz">当前可提现金额(元)</view>
            </view>
            <view @tap="tradeinfo" class="list flex-bet">
                <view class="flex-center trade">
                    <view class="">用户须知</view>
                </view>
                <view class="czhd">
                    <swiper :autoplay="true" :circular="true" duration="500" interval="2000" style="height: 90rpx; width: 70vw" :vertical="true">
                        <swiper-item>
                            <view>请仔细填写账号信息，如果由于您填写错误导致资金流失，平台概不负责</view>
                        </swiper-item>
                        <swiper-item>
                            <view>
                                注意：当前账户余额满
                                <text>{{ fxset.tx_zdmoney }}元</text>
                                后才能申请提现
                            </view>
                        </swiper-item>
                    </swiper>
                </view>
                <image :class="'addright ' + (open ? 'show' : '')" src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/huise@2x.png"></image>
            </view>
            <view class="czhd1" v-if="open">
                <view>请仔细填写账号信息，如果由于您填写错误导致资金流失，平台概不负责</view>
                <view>
                    注意：当前账户余额满
                    <text>{{ fxset.tx_zdmoney }}元</text>
                    后才能申请提现
                </view>
            </view>
            <view class="weui-cells__title">提现方式</view>
            <view class="weui-cells weui-cells_after-title" style="margin-top: 0">
                <radio-group @change="radioChange" class="radio-group" name="radiogroup">
                    <label v-if="iswx == '1'">
                        <view class="weui-cell">
                            <view class="weui-cell__hd">
                                <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/weixin.png"></image>
                            </view>
                            <view class="weui-cell__bd">提现到微信</view>
                            <view class="weui-cell__ft">
                                <radio :checked="txtype == 2" :color="color" value="wxtx"></radio>
                            </view>
                        </view>
                    </label>
                    <label v-if="isyhk == '1'">
                        <view class="weui-cell" style="border-top: 1rpx solid #e6e6e6">
                            <view class="weui-cell__hd">
                                <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/yeqb.png"></image>
                            </view>
                            <view class="weui-cell__bd">提现到银行卡</view>
                            <view class="weui-cell__ft">
                                <radio :checked="txtype == 3" :color="color" value="yhktx"></radio>
                            </view>
                        </view>
                    </label>
                </radio-group>
            </view>
            <view class="txbd">
                <view class="weui-cells weui-cells_after-title" style="margin-top: 0">
                    <view class="weui-cell weui-cell_input">
                        <view class="weui-cell__hd">
                            <view class="weui-label">收款人</view>
                        </view>
                        <view class="weui-cell__bd">
                            <input class="weui-input" name="name" placeholder="请输入姓名" />
                        </view>
                    </view>
                    <view class="weui-cell weui-cell_input">
                        <view class="weui-cell__hd">
                            <view class="weui-label">提现金额</view>
                        </view>
                        <view class="weui-cell__bd">
                            <input class="weui-input" name="je" placeholder="请输入提现金额" type="digit" />
                        </view>
                    </view>
                    <block v-if="txtype == 3">
                        <view class="weui-cell weui-cell_input">
                            <view class="weui-cell__hd">
                                <view class="weui-label">手机号</view>
                            </view>
                            <view class="weui-cell__bd">
                                <input class="weui-input" name="sjh" placeholder="请输入手机号" type="number" />
                            </view>
                        </view>
                        <view class="weui-cell weui-cell_input">
                            <view class="weui-cell__hd">
                                <view class="weui-label">银行卡号</view>
                            </view>
                            <view class="weui-cell__bd">
                                <input class="weui-input" name="yhkh" placeholder="请输入银行卡号" />
                            </view>
                        </view>
                        <view class="weui-cell weui-cell_input">
                            <view class="weui-cell__hd">
                                <view class="weui-label">开户行信息</view>
                            </view>
                            <view class="weui-cell__bd">
                                <input class="weui-input" name="khxx" placeholder="请输入开户行信息" />
                            </view>
                        </view>
                    </block>
                </view>
            </view>
            <view class="weui-btn-area">
                <button class="weui-btn" :disabled="disabled" formType="submit" :style="'background:' + (disabled ? '#e5e5e5' : color) + ';'" type="primary">
                    {{ logintext }}
                </button>
            </view>
        </form>
        <view class="zhezhao" v-if="!fwxy"></view>
        <view class="kcrzxy" v-if="!fwxy">
            <view class="kcrzxyhd">商家提现协议</view>
            <scroll-view scrollY class="kcrzxybd" style="height: 600rpx">
                <rich-text :nodes="fxset.tx_details"></rich-text>
            </scroll-view>
            <view @tap="queren" class="queren">确定</view>
        </view>
    </view>
</template>

<script>
import cardlist from '@/ymq_canyino2o/dist/cardlist/index';
import gettel from '@/ymq_canyino2o/dist/gettel/index';
var app = getApp();
export default {
    components: {
        cardlist,
        gettel
    },
    data() {
        return {
            open: true,
            txtype: 2,
            zhtext: '微信帐号',
            zhtstext: '请输入微信帐号',
            zhtype: 'number',
            disabled: false,
            logintext: '提现',
            fwxy: true,
            commission: '',
            iswx: '',
            iszfb: '',
            isyhk: '',

            fxset: {
                tx_zdmoney: '',
                tx_details: ''
            },

            color: ''
        };
    },
    onLoad: function (t) {
        this.onLoadClone3389(t);
    },
    onReady: function () {},
    onShow: function () {},
    onHide: function () {},
    onUnload: function () {},
    onPullDownRefresh: function () {
        this.onLoadClone3389({});
        uni.stopPullDownRefresh();
    },
    onReachBottom: function () {},
    methods: {
        onLoadClone3389: function (t) {
            var that = this;
            var a = uni.getStorageSync('sjdsjid');
            var o = uni.getStorageSync('users').id;
            console.log(a, o);
            app.globalData.setNavigationBarColor(this);
            uni.setNavigationBarTitle({
                title: '提现'
            });
            app.globalData.util.request({
                url: 'entry/wxapp/Ktx',
                cachetime: '0',

                data: {
                    store_id: a
                },

                success: function (t) {
                    console.log(t);
                    that.setData({
                        commission: t.data
                    });
                }
            });
            app.globalData.util.request({
                url: 'entry/wxapp/system',
                cachetime: '0',

                success: function (t) {
                    console.log(t.data);
                    that.setData({
                        iswx: t.data.is_wx,
                        iszfb: t.data.is_zfb,
                        isyhk: t.data.is_yhk,
                        fxset: t.data
                    });
                }
            });
        },

        lookck: function () {
            this.setData({
                fwxy: false
            });
        },

        queren: function () {
            this.setData({
                fwxy: true
            });
        },

        tradeinfo: function () {
            this.setData({
                open: !this.open
            });
        },

        radioChange: function (t) {
            console.log('radio发生change事件，携带value值为：', t.detail.value);
            if ('zfbtx' == t.detail.value) {
                this.setData({
                    txtype: 1,
                    zhtext: '支付宝帐号',
                    zhtstext: '请输入支付宝帐号',
                    zhtype: 'number'
                });
            }
            if ('wxtx' == t.detail.value) {
                this.setData({
                    txtype: 2,
                    zhtext: '微信帐号',
                    zhtstext: '请输入微信帐号',
                    zhtype: 'text'
                });
            }
            if ('yhktx' == t.detail.value) {
                this.setData({
                    txtype: 3,
                    zhtext: '银行卡号',
                    zhtstext: '请输入银行卡号',
                    zhtype: 'number'
                });
            }
        },

        formSubmit: function (t) {
            var that = this;
            console.log('form发生了submit事件，携带数据为：', t.detail.value);
            var a = uni.getStorageSync('sjdsjid');
            var o = Number(this.commission);
            var i = Number(this.fxset.tx_zdmoney);
            var s = t.detail.value.je;
            var n = t.detail.value.name;
            var l = t.detail.value.sjh;
            var u = t.detail.value.yhkh;
            var d = t.detail.value.khxx;
            var c = t.detail.value.radiogroup;
            console.log(a, o, i, s, n, l, u, d);
            if ('' == c) {
                uni.showModal({
                    title: '提示',
                    content: '请选择提现方式'
                });
                return false;
            }
            if ('wxtx' == c) {
                var x = 1;
            }
            if ('yhktx' == c) {
                x = 2;
            }
            var h = '';
            var r = true;
            if (o < i) {
                h = '佣金满' + i + '才能申请提现';
            } else {
                if ('' == s) {
                    h = '请填写提现金额！';
                } else {
                    if (Number(s) < i) {
                        h = '提现金额未满足提现要求';
                    } else {
                        if (Number(s) > o) {
                            h = '提现金额超出您的实际佣金';
                        } else {
                            if ('' == n) {
                                h = '请填写姓名！';
                            } else {
                                if ('' == s) {
                                    h = '请填写提现金额！';
                                } else {
                                    if ('' == l && '2' == x) {
                                        h = '请填写手机号！';
                                    } else {
                                        if ('' == u && '2' == x) {
                                            h = '请填写银行卡号！';
                                        } else {
                                            if ('' == d && '2' == x) {
                                                h = '请填写开户行信息！';
                                            } else {
                                                that.setData({
                                                    disabled: true,
                                                    logintext: '提交中...'
                                                });
                                                r = false;
                                                app.globalData.util.request({
                                                    url: 'entry/wxapp/StoreTx',
                                                    cachetime: '0',
                                                    data: {
                                                        store_id: a,
                                                        is_brand: x,
                                                        name: n,
                                                        tx_cost: s,
                                                        yhk_num: u || '',
                                                        tel: l || '',
                                                        yh_info: d || ''
                                                    },
                                                    success: function (t) {
                                                        console.log(t);
                                                        if (1 == t.data) {
                                                            uni.showToast({
                                                                title: '提交成功'
                                                            });
                                                            setTimeout(function () {
                                                                uni.navigateBack({});
                                                            }, 1000);
                                                        } else {
                                                            uni.showToast({
                                                                title: '请重试！',
                                                                icon: 'loading'
                                                            });
                                                            that.setData({
                                                                disabled: false,
                                                                logintext: '提现'
                                                            });
                                                        }
                                                    }
                                                });
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (1 == r) {
                uni.showModal({
                    title: '提示',
                    content: h
                });
            }
        },

        formReset() {
            console.log('占位：函数 formReset 未声明');
        }
    }
};
</script>
<style>
@import './wytx.css';
</style>
